/**
 * http://ecma-international.org/ecma-262/6.0/#sec-functiondeclarationinstantiation
 * If the function’s formal parameters do not include any default value initializers then the body declarations are instantiated in the same Environment Record as the parameters. If default value parameter initializers exist, a second Environment Record is created for the body declarations. 
 * 如果函数形参不含有默认参数，那么函数体声明和参数在同一个“独立作用域”中初始化；否则将为函数体申明创建第二个“独立作用域”。。。
 * 延展：
 *  +词法解析、变量提升、EC、ECStack、AO、VO、GO、SCOPE、SCOPE-CHAIN、GC、闭包等
 */

//  作用域就近原则

// 1: 形参默认值，函数内部没有let、var、const重复声明
// debugger
/*var x = 1;

function func(x,y = function () {x = 2}) {
    // scope: 当前上下文，把x=3改成2
    x = 3;
    y();
    console.log(x) //2
}
func(5)
console.log(x) //1
*/

// 2: 形参默认值，函数内部有var重复声明x
// debugger
/*
var x = 1;

function func(x,y = function () {x = 2}) {
    // scope: 当前上下文，把x=3改成2
    var x = 3;
    y();
    console.log(x) //3
}
func(5)
console.log(x) //1
*/


// 2: 形参默认值，函数内部有var重复声明x和y
// debugger
/*
var x = 1;

function func(x,y = function () {x = 2}) {
    // scope: 当前上下文，把x=3改成2
    var x = 3;
    var y = function () {x = 4}
    y();
    console.log(x) //4
}
func(5)
console.log(x) //1
*/
